/*Dart原生网络请求方式*/
import 'dart:convert';
import 'dart:io';

class HttpClientRequest {
  static HttpClient httpClient = HttpClient();
  static String baseUrl = '';
  static var responseBody;

  static Future<dynamic> init(String url) async {
    baseUrl = url;
  }

  static void get() async {
    var request = await httpClient.getUrl(Uri.parse(baseUrl));
    var response = await request.close();
    if (response.statusCode == 200) {
      responseBody = await response.transform(utf8.decoder).join();
      responseBody = json.decode(responseBody);
      print(responseBody.toString());
    } else {
      print('error');
    }
  }

  static void post() async {
    var request = await httpClient.postUrl(Uri.parse(baseUrl));
/*设置请求头*/
    request.headers.set('Authorization', '');
    request.headers.set('platform', '3');
    request.headers.set('Authorization', '');
  }
}
